import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { VersioningType } from "@nestjs/common";
import { ValidationPipe } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";

async function bootstrap() {
    const app = await NestFactory.create(AppModule, { cors: true });
    const configService = app.get(ConfigService);
    app.useGlobalPipes(
        new ValidationPipe({ whitelist: true, transform: true, transformOptions: { enableImplicitConversion: true } })
    );
    app.enableVersioning({
        type: VersioningType.URI,
        defaultVersion: configService.get<string>("API_VERSION")
    });
    const config = new DocumentBuilder()
        .setTitle("Е-КАМПУС API")
        .setVersion(configService.get<string>("API_VERSION"))
        .addBearerAuth({ in: "header", type: "http" }, "bearer")
        .build();
    const document = SwaggerModule.createDocument(app, config);
    SwaggerModule.setup("swagger", app, document, {
        swaggerOptions: { defaultModelsExpandDepth: -1 }
    });
    await app.listen(3000);
}
bootstrap();
